<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
    <script src="js/jquery.js"></script>
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script>
        $(function () {
            //获取员工信息
            var url = window.location.href;
            var id = url.split('?')[1];
            $.ajax({
               url: "/base/emp/getById?"+id,
               type: "get",
               dataType: "JSON",
               success: function (data) {
                   if (data){
                       var name = data.name;
                       var id = data.id;
                       var sex = data.sex;
                       var age = data.age;
                       $("input[name='id']").val(id);
                       $("input[name='age']").val(age);
                       $("input[name='name']").val(name);
                       if (sex == 1){
                           $("input[title='男']").prop("checked",true);
                       }else if (sex == 2) {
                           $("input[title='女']").prop("checked",true);
                       }
                       layui.form.render("radio");
                   }
               }
            });
            $("#submit").on('click',function () {
                if (confirm('确定要提交吗？')){
                    $.ajax({
                        url: '/base/emp/update?' ,
                        data: $("form").serialize(),
                        type: 'post',
                        success: function (data) {
                            if (data && data == 1){
                                alert('修改成功');
                                var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
                                parent.layer.close(index);//执行关闭
                            }else {
                                alert('修改失败');
                            }
                        }
                    })
                }
            });
        });
    </script>
</head>
<body>
<form class="layui-form">
    <input name="id" type="hidden" value="1">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入名字" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-block">
            <input type="number" name="age" required lay-verify="required" placeholder="请输入年龄" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男">
            <input type="radio" name="sex" value="2" title="女" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="submit" type="button" class="layui-btn" lay-submit lay-filter="formDemo">确定修改</button>
        </div>
    </div>
</form>
</body>
</html>